
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Spring Boot如何优化REST API的性能 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Spring Boot如何优化REST API的性能 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">为什么推荐在Spring Boot中启用HTTP/2？它带来了哪些关键好处？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">推荐启用HTTP/2是因为它支持多路复用、头部压缩和服务器推送，这些特性可以显著提升API的响应效率。</div>
          </div>
          <div class="card-source">来源: 1.1 启用 HTTP/2</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">传统的同步阻塞REST API在高并发下有何弊端？异步处理如何解决这个问题？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">同步阻塞API在高并发场景下可能导致线程资源耗尽。异步处理通过在等待耗时操作时释放服务器线程资源，使得少量线程可以处理大量并发请求，从而解决了这个问题。</div>
          </div>
          <div class="card-source">来源: 1.3 异步非阻塞处理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在JPA中，如何有效避免“N+1查询问题”以优化数据访问性能？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">为避免“N+1查询问题”，可以在JPA中通过使用`@EntityGraph`注解或编写显式的JOIN查询来一次性加载关联数据。</div>
          </div>
          <div class="card-source">来源: 2.1 减少数据库查询次数</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在Spring Boot中启用Gzip压缩的目的是什么？如何配置以避免对过小响应进行压缩？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">启用Gzip压缩的目的是通过压缩HTTP响应体来显著减少网络传输量。可以通过设置`server.compression.min-response-size`属性（例如设置为1024字节）来指定一个最小响应大小，只有超过这个大小的响应才会被压缩。</div>
          </div>
          <div class="card-source">来源: 3.1 Gzip 压缩</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">为了减少不必要的网络数据传输，文档中提到了哪两种减少JSON响应体大小的方法？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档中提到了两种方法：1. 使用`@JsonIgnore`注解来忽略模型中不需要序列化到客户端的字段。2. 使用数据传输对象（DTO），只包含客户端必需的字段，从而精确控制返回的数据。</div>
          </div>
          <div class="card-source">来源: 3.3 减少 JSON 数据大小</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">实践</div>
          <div class="card-question">为什么在高并发应用中，将日志级别从DEBUG调整为INFO或WARN是一项重要的性能优化措施？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">实践</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">因为详细的日志记录（尤其是DEBUG级别）会导致性能下降，在高并发场景下尤其如此。调整为INFO或WARN级别可以显著减少日志开销，提升应用的性能。</div>
          </div>
          <div class="card-source">来源: 4.2 减少日志开销</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">Spring Boot Actuator在API性能优化过程中扮演什么角色？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Spring Boot Actuator主要扮演性能监控的角色。它通过提供监控端点来暴露应用的各项关键指标（如响应时间、请求数量），帮助开发者发现并定位性能瓶颈。</div>
          </div>
          <div class="card-source">来源: 5.1 启用 Actuator 性能监控</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">与传统的REST相比，GraphQL在优化数据传输方面有何核心优势？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">GraphQL的核心优势在于它允许客户端按需返回数据，这有效避免了REST API中常见的不必要的数据传输问题，从而提升了性能。</div>
          </div>
          <div class="card-source">来源: 6.1 使用 GraphQL 替代 REST</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">在高负载或依赖服务不稳定的情况下，为什么要引入限流（Rate Limiting）和熔断（Circuit Breaker）机制？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">引入限流和熔断机制是为了保护系统在高负载或异常情况下的稳定性。这两种机制可以防止系统因流量过大或下游服务故障而崩溃。</div>
          </div>
          <div class="card-source">来源: 6.3 限流与熔断</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
